<template>
	<view class="main">
		<view class="class_h" style="background-color: #fff">
			<view class="top" @click="return_step">					
				<image src="../../../static/resource/back.png" mode="aspectFill" style="width: 74px;height: 30px;"></image>				
			</view>
			<text class="task_name">血压历史数据</text>
		</view>	
		
		<view>
		  <swiper class="tab-content"  duration="300" bindchange="changeTab" :style="{'height':winHeight+'px'}">
				<!-- 全部 -->
				<swiper-item>
					<scroll-view :scroll-y="true" class="new-list-box" @scrolltolower="allLoadMore" scroll-top="scrollTop" scroll-with-animation :refresher-enabled="true" refresher-threshold="80" refresher-default-style="white" refresher-background="white" :refresher-triggered="triggered" @refresherrefresh="onAllRefresh">
						<block v-if="allTabList.length > 0">
						  <view class="new-list-item" v-for="(item,index) in allTabList" :key="index">  				                  
							<view class="content-deadline mb-15 text-xsl flex justify-between" style="width: 100%;">
								<view class="flex flex-direction ">
									<view class="flex align-center text-center">
										<image src="/static/resource/measure.png" mode="aspectFill" style="width: 3px;height: 10px;"></image>
										<text class="ml-20">{{item.dateTime}}</text>
									</view>
									<view class="flex mt-20">
										<text class="flex" >{{item.sugar_value}}</text>
										 <text class="ml-40 flex" >舒张压：{{item.blood_dbp}}</text>
										  <text class="ml-40 flex" >收缩压：{{item.blood_sbp}}</text>
									</view>									
								</view>
								<view class="flex mr-40">
									<u-button type="primary" :plain="true" text="删除"  iconColor="#FFDFDF" color="#EA3B3D" @click="sugar_del(item.id)"></u-button>
								</view>					
							</view>					
						  </view>
						</block>   												  
					</scroll-view>
				</swiper-item>       
			</swiper>				
		</view>	
	</view>	
</template>
<script>
	export default {
			data() {
				return {
					currentTab:1,
					pageNo:1,
					allTabList:[],
					winHeight:'',
					scrollTop: 0, // 设置竖向滚动条位置
					triggered: false, // 下拉是否激活
					recordCount:1,
				}
			},
			onLoad() {
				let height = uni.getSystemInfoSync().windowHeight;
				this.winHeight = (height - 150);			
				this._requestPageList(true);
			},
			methods:{
				...getApp().globalData.function,
				//删除信息
				sugar_del(id){
					this.$showModal({content: '确定删除信息嘛？',confirmColor:'#3484E6'}).then(res=>{
					  if(res.confirm){
						let  token=uni.getStorageSync('userInfo').token
					    this.$http.sugarDel({id,token}).then(res=>{
					      this.$showToast(res.resMessage)
					      setTimeout(()=>{
					        this.allTabList=[]
							this.pageNo=1
					        this._requestPageList(true);
					      },2000)		          
					      return
					    })       
					  }else{
					  }
					})
				},			
				return_step(){
					this.$routers.router('/pages/class/index','switchTab') 
				},
				changeNav(e){
					let currentIndex = e.target.dataset.current;
					if (this.currentTab == currentIndex) {      
					    return false;
					} else {
					    this.pageNo=1;
						this.currentTab= currentIndex
					}
					this.allTabList=[];
					this._requestPageList(true);
				},			
				
				// 参数
				_requestPageList(isLoadMore = false, callback) {
				  if(!isLoadMore){
					this.allTabList=[]; // 全部       
					this.pageNo= 1;
					
				  }
				  let opt = {
					pageNo :this.pageNo,				
					token:uni.getStorageSync('userInfo').token,
					blood_type:2
				  }    
				  this._requestPageListCom("virtualTaskList", opt, callback);
				},
				// 列表接口
				_requestPageListCom(url, params, callback) {    
				  this.$http.blood_measure_list(params).then(res => {
					if (res.resCode == "9999") {
					  let oldList = [];
					  oldList = this.allTabList;       
					  const newGoodsList = res.data.list
					  const allData = [...oldList, ...newGoodsList]
					  // console.log(allData,'allData')     
					  this.allTabList=allData
					  this.recordCount=res.data.page
					  if(callback && typeof callback === 'function'){
						callback()
					  }
					}
				  })
				},			  
				// 上拉加载  滚动到底部/右边时触发
				allLoadMore(e){
					let _self = this;
					if (this._allLoadMore) return
					this._allLoadMore = true;
					this.pageNo= ++_self.pageNo				
					this._requestPageList(true, () => {
					  _self._allLoadMore = false;
					});
				},
				
				// 下拉刷新接口
				onAllRefresh() {
				 // 开启下拉自定义样式
					this.triggered = true;
		            this.pageNo=1;
					this._requestPageList(false, () => {
						// 当处理完数据刷新后，wx.stopPullDownRefresh可以停止当前页面的下拉刷新
						this.triggered = false;
					});    
				}				
			}
		}
</script>

<style>
	@import url("./index.css");
</style>